package com.ziyun.erp.web.modules.userTeam.controller;

import com.ziyun.erp.modules.userTeam.entity.UserTeamEntity;
import com.ziyun.erp.modules.userTeam.entity.UserTeamVo;
import com.ziyun.erp.modules.userTeam.service.UserTeamService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;



/**
 * 团队表
 *
 * @author jiangli
 * @email 
 * @date 2018-11-16 16:19:35
 */
@RestController
@RequestMapping("userTeam/userteam")
public class UserTeamController {
    @Autowired
    private UserTeamService userTeamService;
//    @Autowired
//    private DistributionService distributionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("userTeam:userteam:list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = userTeamService.list(params);

        return R.ok().put("page", page);
    }

    /**
     * 审核通过
     */
    @RequestMapping("/audit")
    public R audit(@RequestBody UserTeamVo userTeamVo){
        return userTeamService.audit(userTeamVo);
    }

    /**
     * 审核拒绝
     */
    @RequestMapping("/pass")
    public R pass(@RequestBody UserTeamVo userTeamVo){

        return userTeamService.pass(userTeamVo);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{teamId}")
    @RequiresPermissions("userTeam:userteam:info")
    public R info(@PathVariable("teamId") Integer teamId){
        UserTeamEntity userTeam = userTeamService.selectById(teamId);

        return R.ok().put("userTeam", userTeam);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("userTeam:userteam:save")
    public R save(@RequestBody UserTeamEntity userTeam){
        userTeamService.insert(userTeam);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("userTeam:userteam:update")
    public R update(@RequestBody UserTeamEntity userTeam){
        ValidatorUtils.validateEntity(userTeam);
        userTeamService.updateById(userTeam);
        
        return R.ok();
    }

    /**
     * 单行删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody UserTeamEntity userTeam){
        //userTeam.setDelFlag(true);设置逻辑删除为true
        userTeamService.updateById(userTeam);
        return R.ok();
    }

//    @RequestMapping("/checkAgent")
//    public R checkAgent(@RequestBody VerifyLeaderParam var1){
//        var1.setSourceType(DistributionType.agent.name());
//        UcenterResult<?> result = distributionService.verifyLeader(var1);
//        if(result.getCode() == ResultCode.SUCCESS.getCode()){
//            return R.ok(result.getMessage());
//        }else {
//            return R.error(result.getMessage().substring(0,result.getMessage().length()>50?50:result.getMessage().length()));
//        }
//    }

}
